package me.numark.view;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import butterknife.ButterKnife;
import butterknife.InjectView;
import me.numark.R;
import me.numark.model.News;
import me.numark.utils.Utils;

/**
 * Created by tian on 15/5/3:下午5:53.
 */
public class NewsListItemViewHolder implements OnClickListener {

    @InjectView(R.id.time_label)
    public TextView date;

    @InjectView(R.id.pic)
    public ImageView pic;

    @InjectView(R.id.title)
    public TextView title;

    @InjectView(R.id.news_src)
    public TextView newsSrc;

    @InjectView(R.id.mark_count)
    public TextView markCount;

    @InjectView(R.id.watch_count)
    public TextView watchCount;

    @InjectView(R.id.news_sharer)
    TextView newsSharer;

    private Activity mActivity;

    public NewsListItemViewHolder(Fragment fragment, View view) {
        ButterKnife.inject(this, view);
        mActivity = fragment.getActivity();
        initViews();
    }

    public NewsListItemViewHolder(Activity activity, View view) {
        ButterKnife.inject(this, view);
        mActivity = activity;
        initViews();
    }

    private void initViews() {
        markCount.setOnClickListener(this);
        newsSharer.setOnClickListener(this);
    }
    private News mNews;
    public void bindData(News news) {
        mNews = news;
        date.setText(Utils.getDatetimeStr(news.create_timestamp * 1000));
        if (TextUtils.isEmpty(news.face_img)) {
            pic.setVisibility(View.GONE);
        } else {
            Picasso.with(mActivity).load(news.face_img).into(pic);
        }
        title.setText(news.title);
        newsSrc.setText(news.from_str + " · ");
        newsSharer.setText(news.by_user.nick);
        markCount.setText(Integer.toString(news.topic_num));
        watchCount.setText(Integer.toString(news.read_num));
    }

    @Override
    public void onClick(View v) {

    }
}
